﻿@model Resto.CostControl.Core.Dish
@{
    ViewBag.Title = "菜肴维护";
    Layout = "~/Views/Shared/_LayoutForm.cshtml"; 
}
@using (Html.AjaxBeginForm("Save"))
{ 
    <!-- 主表 --> 
    <div class="pageFormContent" style="width: 600px">
        @Html.HiddenFor(model => model.Id)
        @Html.DWZTextBoxFor(model => model.Name).Required()
        @Html.DWZTextBoxFor(model => model.Code)
        @Html.DWZDropDownListFor(model => model.Category, "DishType")
        @Html.DWZDropDownListFor(model => model.CookType, "CookType")
        @Html.DWZTextBoxFor(model => model.Cost).Number()
        @Html.DWZTextBoxFor(model => model.Price).Number()
        @Html.DWZDropDownListFor(model => model.MainMaterialType, "MaterialCategory")
        @Html.DWZTextAreaFor(model => model.Remark)
    </div>
    <div class="clear">
    </div>
    <!-- 子表 --> 
    <div class="pageFormDetailList">
        @Html.Css("flexigrid", "tmpl", "list")
        @Html.Js("flexigrid", "tmpl", "list")
        @(        
 Html.DWZGridFor<Resto.CostControl.Core.DishMaterial>()
        .Title("品名列表")
        .ID("MaterialList")
        .Action(@Url.Action("EditList"))
            .ExtParam(new { ParentId = "$('#Id').val()" })
        .Width(580)
        .Height(100)
        .Columns(col =>
        {
            col.Bind(e => e.Id).IsKey().Sortable(false);
            col.Bind(e => e.Code).Width(60).Sortable(false);
            col.Bind(e => e.Name).Width(100).Align(FlexiGridAlign.Left).Sortable(false);
            col.Bind(e => e.CurrentPrice).Width(50).Align(FlexiGridAlign.Right).Sortable(false);
            col.Bind(e => e.Category).Width(50).EnumKey("MaterialCategory").Sortable(false);
            col.Bind(e => e.Weight).Template(@Html.TextBox("Weight", "${Weight}", new { style = "text-align:right;width:56px" }).ToString()).Width(60).Sortable(false);
            col.Bind(e => e.Id, "操作", 60).Sortable(false)
               .Template(Url.GridLink("delete", "删除", "DeleteRow('${Id}')"));
        })
        .ShowCheckBox(false)
        .UsePager(false)
        .Buttons(btn =>
        {
            btn.Bind("Add", "选择品名", FlexiGridButtonType.Add).OnPress("SelectMaterial");
        })
    )
    </div>
}
@Html.FormBar()
<script type="text/javascript">
    function SelectMaterial(e) {
        OpenModalDialog('@Url.Action("LookUp")', { width: 840, height: 400, onclose: function (MaterialData) {
            if (MaterialData) {
                $("#MaterialList").flexAddRows(MaterialData);
            }
        }
        });
    }

    function DeleteRow(id) {
        $("#MaterialList").flexDeleteRowData(id);
    }
</script>
